package life.system.order.listener;

import life.system.common.utils.R;
import life.system.order.service.impl.PaymentInfoServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;


@RestController
@RequestMapping("/order/app")
public class OrderPayedListener {


    @Autowired
    PaymentInfoServiceImpl paymentInfoService;

    /**
     * 成功支付通知
     * 1、修改订单状态
     * 2、保存支付信息
     */
    @GetMapping("/payed/notify")
    public R handleAlipayed(@RequestParam String orderSn) {
        try {
            // 1、保存交易流水
            String qrCode = paymentInfoService.saveByOrderSn(orderSn);
            return R.ok().put("data", qrCode);
        } catch (Exception e) {
            return R.error();
        }
    }

}